
#include "PipelineTaskInfo.h"

#ifdef TTG_PL_VISUALIZER

using namespace ttg_internal::pipeline;

//------------------------
//--- PipelineTaskInfo ---
//------------------------

PipelineTaskInfo::PipelineTaskInfo()
{
	this->expected_time = 0.0f;
	this->elapsed_time = 0.0f;
	this->start_time = 0.0f;
}

PipelineTaskInfo::PipelineTaskInfo(double start_time,
								   double elapsed_time,
								   double expected_time)
{
	this->start_time = start_time;
	this->elapsed_time = elapsed_time;
	this->expected_time = expected_time;
}

void PipelineTaskInfo::store(ttg::extras::XMLTree &xml)
{
	xml.addSectionAndOpen("Task");
	xml.addDoubleAttribute("start", this->getStartTime());
	xml.addDoubleAttribute("elapsed", this->getElapsedTime());
	xml.addDoubleAttribute("expected", this->getExpectedTime());
	if (getTag() != "")
		xml.addStringAttribute("tag", getTag().c_str());
	xml.closeSection();
}

PipelineTaskInfo PipelineTaskInfo::create(ttg::extras::XMLTree &xml)
{
	//Getting main attributes.
	double t_start;
	double elapsed;
	double expected;
	if (!xml.getDoubleAttribute("start", t_start) ||
		!xml.getDoubleAttribute("elapsed", elapsed) ||
		!xml.getDoubleAttribute("expected", expected))
		throw ttg::Error(ttg::Error::LOCAL, "TaskInfo", "create",
						 "Cannot get time attribute(s)");
	PipelineTaskInfo res(t_start, elapsed, expected);
	//Getting string tag.
	const char *tag;
	if (xml.getStringAttribute("tag", tag))
		res.setTag(std::string(tag));
	return res;
}

#endif
